<template>
  <a-input-number
    v-bind="$attrs"
    v-on="$attrs"
    :disabled="disabled"
    :min="min"
    :max="max"
    hide-button
    placeholder="请输入"
    :allow-clear="allowClear"
    :formatter="formatter"
    model-event="input"
  >
    <template #append v-if="unit || $slots.append">
      <slot name="append">
        {{ unit }}
      </slot>
    </template>
  </a-input-number>
</template>

<script setup name="sorderConfigPriceInputNumber">
  defineProps({
    min: {
      type: Number,
      default: 0,
    },
    max: Number,
    disabled: {
      type: Boolean,
      default: false,
    },
    allowClear: {
      type: Boolean,
      default: true,
    },
    unit: {
      type: String,
      default: '元/日',
    },
  })

  // 仅允许输入两位小数
  const formatter = (value) => {
    const values = value.split('.')
    if (values[1]) values[1] = String(values[1]).substring(0, 2)
    return values.join('.')
  }
</script>
